package cn.lkp.mall.cart.vo;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
public class CartVo {
    List<CartItemVo> items;
    private Integer countNum;//商品总数量
    private Integer countType;//商品种类
    private BigDecimal totalAmount;//商品总价
    private BigDecimal reduce = new BigDecimal("0.00"); //减免价格

    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if(items != null && items.size()>0){
            for (CartItemVo item : items) {
                //每种商品数量的累加
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if(items != null && items.size()>0){
            for (CartItemVo item : items) {
                //每种商品数量的累加
                count += 1;
            }
        }
        return count;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if(!CollectionUtils.isEmpty(items)){
            for (CartItemVo item : items) {
                if(item.getCheck()){
                    BigDecimal totalPrice = item.getTotalPrice();
                    amount = amount.add(totalPrice);
                }
            }
        }
        return amount.subtract(this.getReduce());
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
